import React, { Component } from 'react';
import MyHeader from './components/MyHeader'
import Swipper from './components/Swipper'
import Search from '@/components/search/Search'
import HotCate from './components/HotCate'
import Good from './components/Good'
import {GetHomeAsync,GEtGOODDATAsync} from './actionType';
import { connect } from "react-redux";
@connect(//装饰器模式使用redux
  state=>({
    hotCate:state.cook.hotcate,
    goodArr:state.cook.goodArr,
  }),
  dispatch=>({
    getHome(){
         dispatch(GetHomeAsync())
       },
       getGoodA(){
         dispatch(GEtGOODDATAsync())
       }
     })
)
class Cookbook extends Component {
  componentDidMount(){
   this.props.getHome()
   this.props.getGoodA()
  }
  render() {
    return <div>
        {/* 头组件 */}
         <MyHeader />
         {/* 轮播 */}
         <Swipper />
         {/* search */}
         <Search />
         {/* hotCate */}
         <HotCate arr={this.props.hotCate}/>
         {/* good */}
         <Good arr={this.props.goodArr}/>
      </div>
  }
}
export default Cookbook
// const mapState=(state)=>({
// hotCate:state.cook.hotcate,
// goodArr:state.cook.goodArr,
// })
// const mapDispatch=(dispatch)=>({
//   getHome(){
//     dispatch(GetHomeAsync())
//   },
//   getGoodA(){
//     dispatch(GEtGOODDATAsync())
//   }
// })
// export default connect(mapState, mapDispatch)(Cookbook);
